/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsProductCategoryDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsProductCategoryDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsProductCategoryDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsProductCategoryDO objcmsProductCategoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCategoryCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsHomePage", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductCategoryDO.IsHomePage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MetaDes", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.MetaDes;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MetaTag", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.MetaTag;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PageTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.PageTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Content", SqlDbType.NText);
            Sqlparam.Value = objcmsProductCategoryDO.Content;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsProductCategoryDO objcmsProductCategoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ParentID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.ParentID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsHomePage", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductCategoryDO.IsHomePage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MetaDes", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.MetaDes;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MetaTag", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.MetaTag;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PageTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductCategoryDO.PageTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Content", SqlDbType.NText);
            Sqlparam.Value = objcmsProductCategoryDO.Content;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsProductCategoryDO objcmsProductCategoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsProductCategoryDO Select(cmsProductCategoryDO objcmsProductCategoryDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductCategoryDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                    objcmsProductCategoryDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                if (!Convert.IsDBNull(dr["ProductCategoryCode"]))
                    objcmsProductCategoryDO.ProductCategoryCode = Convert.ToString(dr["ProductCategoryCode"]);
                if (!Convert.IsDBNull(dr["ProductCategoryTitle"]))
                    objcmsProductCategoryDO.ProductCategoryTitle = Convert.ToString(dr["ProductCategoryTitle"]);
                if (!Convert.IsDBNull(dr["Description"]))
                    objcmsProductCategoryDO.Description = Convert.ToString(dr["Description"]);
                if (!Convert.IsDBNull(dr["OrderID"]))
                    objcmsProductCategoryDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                if (!Convert.IsDBNull(dr["ParentID"]))
                    objcmsProductCategoryDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                if (!Convert.IsDBNull(dr["IsHomePage"]))
                    objcmsProductCategoryDO.IsHomePage = Convert.ToBoolean(dr["IsHomePage"]);
                if (!Convert.IsDBNull(dr["MetaDes"]))
                    objcmsProductCategoryDO.MetaDes = Convert.ToString(dr["MetaDes"]);
                if (!Convert.IsDBNull(dr["MetaTag"]))
                    objcmsProductCategoryDO.MetaTag = Convert.ToString(dr["MetaTag"]);
                if (!Convert.IsDBNull(dr["PageTitle"]))
                    objcmsProductCategoryDO.PageTitle = Convert.ToString(dr["PageTitle"]);
                if (!Convert.IsDBNull(dr["Content"]))
                    objcmsProductCategoryDO.Content = Convert.ToString(dr["Content"]);

            }
            return objcmsProductCategoryDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsProductCategoryDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsProductCategoryDO objcmsProductCategoryDO = new cmsProductCategoryDO();
                    if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                        objcmsProductCategoryDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                    if (!Convert.IsDBNull(dr["ProductCategoryCode"]))
                        objcmsProductCategoryDO.ProductCategoryCode = Convert.ToString(dr["ProductCategoryCode"]);
                    if (!Convert.IsDBNull(dr["ProductCategoryTitle"]))
                        objcmsProductCategoryDO.ProductCategoryTitle = Convert.ToString(dr["ProductCategoryTitle"]);
                    if (!Convert.IsDBNull(dr["Description"]))
                        objcmsProductCategoryDO.Description = Convert.ToString(dr["Description"]);
                    if (!Convert.IsDBNull(dr["OrderID"]))
                        objcmsProductCategoryDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                    if (!Convert.IsDBNull(dr["ParentID"]))
                        objcmsProductCategoryDO.ParentID = Convert.ToInt32(dr["ParentID"]);
                    if (!Convert.IsDBNull(dr["IsHomePage"]))
                        objcmsProductCategoryDO.IsHomePage = Convert.ToBoolean(dr["IsHomePage"]);
                    if (!Convert.IsDBNull(dr["MetaDes"]))
                        objcmsProductCategoryDO.MetaDes = Convert.ToString(dr["MetaDes"]);
                    if (!Convert.IsDBNull(dr["MetaTag"]))
                        objcmsProductCategoryDO.MetaTag = Convert.ToString(dr["MetaTag"]);
                    if (!Convert.IsDBNull(dr["PageTitle"]))
                        objcmsProductCategoryDO.PageTitle = Convert.ToString(dr["PageTitle"]);
                    if (!Convert.IsDBNull(dr["Content"]))
                        objcmsProductCategoryDO.Content = Convert.ToString(dr["Content"]);
                    arrcmsProductCategoryDO.Add(objcmsProductCategoryDO);
                }
            }
            return arrcmsProductCategoryDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectById(int productCategoryId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = productCategoryId;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectHomePage()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetHomePage";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectHomePage(int top)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetHomePageByTop";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Top", SqlDbType.Int);
            Sqlparam.Value = top;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectRoot()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetRoot";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        
        public DataTable SelectByParent(int parentId)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetByParent";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ParentId", SqlDbType.Int);
            Sqlparam.Value = parentId;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        

        #endregion


        public cmsProductCategoryDO Selectbycode(cmsProductCategoryDO DO)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProductCategory_GetByCode";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCategoryCode", SqlDbType.NVarChar);
            Sqlparam.Value = DO.ProductCategoryCode;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                    DO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                if (!Convert.IsDBNull(dr["ProductCategoryCode"]))
                    DO.ProductCategoryCode = Convert.ToString(dr["ProductCategoryCode"]);
                if (!Convert.IsDBNull(dr["ProductCategoryTitle"]))
                    DO.ProductCategoryTitle = Convert.ToString(dr["ProductCategoryTitle"]);
                if (!Convert.IsDBNull(dr["Description"]))
                    DO.Description = Convert.ToString(dr["Description"]);
                if (!Convert.IsDBNull(dr["OrderID"]))
                    DO.OrderID = Convert.ToInt32(dr["OrderID"]);
                if (!Convert.IsDBNull(dr["ParentID"]))
                    DO.ParentID = Convert.ToInt32(dr["ParentID"]);

            }
            return DO;
        }
    }

}
